<?php
// $Id$

/**
 * Controller_Admin_System 控制器
 */
class Controller_Admin_System extends Controller_Abstract
{	
	function IntToStr($v)
	{
		return (string)"'".$v."'";
	}
	function actionlog()
	{
	    $this->union_table = Syslog::meta();
	    $this->lists($this->_format_appendSql());
	}
	function actionaboutus()
	{
	
	    if($this->_context->isPOST()){
	    	$acct = acct::find(array("id"=>$_SESSION['acct']['id']))->getOne();

			$acct->name=$this->_context->name;
			$acct->app_id=$this->_context->app_id;
			$acct->app_secret=$this->_context->app_secret;
			$acct->key=$this->_context->key;
			$acct->mch_id=$this->_context->mch_id;
			$acct->cert_pem=$this->_context->cert_pem;
			$acct->key_pem=$this->_context->key_pem;


			$acct->aliaccessid = $this->_context->aliaccessid;
			$acct->aliaccesskey = $this->_context->aliaccesskey;
			$acct->pushdomain = $this->_context->pushdomain;
			$acct->playdomain = $this->_context->playdomain;
			$acct->pushauthkey = $this->_context->pushauthkey;
			// $acct->praiseadd = $this->_context->praiseadd;
			$acct->paper_category_deep = $this->_context->paper_category_deep;
			$acct->show_join_user = $this->_context->show_join_user;
			
			$acct->aodian_accessid = $this->_context->aodian_accessid;
			$acct->aodian_accesskey = $this->_context->aodian_accesskey;
			$acct->aodian_auth = $this->_context->aodian_auth;

			
			$acct->address=$this->_context->address;
			$acct->isup=$this->_context->isup;
			$acct->dec=$this->_context->dec;
			$acct->sh_version=$this->_context->sh_version;
			$acct->login_logo=$this->_context->login_logo;
			$acct->background_image=$this->_context->background_image;
			$acct->applet_code=$this->_context->applet_code;
			$acct->shipfee_open=$this->_context->shipfee_open;
			if($_SESSION['acct']['id']==1){
				$acct->socket=$this->_context->socket;
			}
			$acct->freeshipfee_orderprice=$this->_context->freeshipfee_orderprice;
			$acct->save();

	        Syslog::logs ( '编辑信息,id :' . $_SESSION['acct']['id'] );

	        $this->success('设置成功');
	    }else{
	    	$acctInfo = acct::find(array("id"=>$_SESSION['acct']['id']))->getOne();
	    	$this->_view['info'] = $acctInfo;
	    	//var_dump($acctInfo);
	    }
	    

	
	}
	
	function actionapplydec()
	{
	
	    if($this->_context->isAJAX()){
	
	
	        $aboutus=($this->_context->applydec);
	
	        Helper_Common::setPublic('applydec',$aboutus,$_SESSION['acct']['id']);
	        $this->success('设置成功');
	    }
	
	}
	
	function actionconfig(){
		$config = pubconfig::find("agent_id = ?",$_SESSION['acct']['id'])->getAll();
		if($this->_context->isPOST()){
			foreach ($config as $value) {
				
				$name = $value->name;
				$value->value = $this->_context->$name;
				$value->save();
			}
			$this->success('设置成功');
		}else{
			
			$this->_view['info'] = $config;
		}
	}
	
	/*
	 * 登陆页面logo和后台左上角图片管理
	 */
	function  actionLogoImg(){
	    $agentid=intval($this->_context->agent_id);
	    $this->_view['agent_id'] = $agentid;
	    if($this->_context->isPOST())
	    {
	        $agentid=intval($this->_context->agent_id);
	        // $loginlogo = trim($this->_context->loginlogo);
	        $systemlogo = trim($this->_context->systemlogo);
	        // $va=Helper_Common::getPublicSet('loginlogo',$agentid);
	        $vb=Helper_Common::getPublicSet('systemlogo',$agentid);
	        $host = Helper_Common::getRequestHost();
	        // 	        global $root_dir;
	        // 	        if(!empty($va) && $va<> $loginlogo ){
	        // 	            $path = str_replace($host, '', $va);
	        // 	            $oldfilepath = $root_dir . '/' . 'public'. '/'.$path;
	        // 	            Helper_Common::safeDelFile($oldfilepath);
	        // 	        }
	        // 	        if(!empty($vb) && $vb<> $systemlogo){
	        // 	            $path = str_replace($host, '', $vb);
	        // 	            $oldfile = $root_dir . '/' . 'public'. '/'.$path;
	        // 	            Helper_Common::safeDelFile($oldfile);
	        // 	        }
	        //   Helper_Common::setPublic('loginlogo',$loginlogo, $agentid);
	        Helper_Common::setPublic('systemlogo',$systemlogo, $agentid);
	        $this->success('编辑成功');
	    }
	}

}


